<template>
  <div class="mod-demo-echarts">
    <el-row :gutter="30">
      <el-col :span="23">
        <el-card>
          <div id="J_chartPieBox" class="chart-box"></div>
        </el-card>
      </el-col>
      <el-col :span="23">
        <el-card>
          <div id="J_chartPieBoxLevel" class="chart-box"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>


<script>
import echarts from 'echarts'
export default {
  data () {
    return {
      chartLine: null,
      chartBar: null,
      chartPie: null,
      chartScatter: null,
      countbook: [],
      chartPieLevel: null,
      countbookcert: []
    }
  },
  mounted () {
    this.initChartPie()
    this.initChartPieLevel()
  },
  activated () {
    if (this.chartPie) {
      this.chartPie.resize()
    }
    if (this.chartPieLevel) {
      this.chartPie.resize()
    }
  },
  methods: {
    // 饼状图
    initChartPie () {
      let countbookM = []
      this.$http({
        url: this.$http.adornUrl('/bs_book/bsbook/countBookNum'),
        method: 'get'
      }).then(({data}) => {
        this.countbook = data.date
        countbookM = this.countbook
        var option = {
          backgroundColor: '#2c343c',
          title: {
            text: '书籍名称借阅图表展示',
            left: 'center',
            top: 20,
            textStyle: {
              color: '#ccc'
            }
          },
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          visualMap: {
            show: false,
            min: 80,
            max: 600,
            inRange: {
              colorLightness: [0, 1]
            }
          },
          series: [
            {
              name: '访问来源',
              type: 'pie',
              radius: '55%',
              center: ['50%', '50%'],
              data: countbookM.sort(function (a, b) {
                return a.value - b.value
              }),
              roseType: 'radius',
              label: {
                normal: {
                  textStyle: {
                    color: 'rgba(255, 255, 255, 0.3)'
                  }
                }
              },
              labelLine: {
                normal: {
                  lineStyle: {
                    color: 'rgba(255, 255, 255, 0.3)'
                  },
                  smooth: 0.2,
                  length: 10,
                  length2: 20
                }
              },
              itemStyle: {
                normal: {
                  color: '#c23531',
                  shadowBlur: 200,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              },
              animationType: 'scale',
              animationEasing: 'elasticOut',
              animationDelay: function (idx) {
                return Math.random() * 200
              }
            }
          ]
        }
        this.chartPie = echarts.init(document.getElementById('J_chartPieBox'))
        this.chartPie.setOption(option)
        window.addEventListener('resize', () => {
          this.chartPie.resize()
        })
      })
    },
    initChartPieLevel () {
      let countbookcertM = []
      this.$http({
        url: this.$http.adornUrl('/bs_book/bsbook/countBookCert'),
        method: 'get'
      }).then(({data}) => {
        this.countbookcert = data.date
        countbookcertM = this.countbookcert
        var option = {
          backgroundColor: '#2c343c',
          title: {
            text: '书籍类别借阅图表展示',
            left: 'center',
            top: 20,
            textStyle: {
              color: '#ccc'
            }
          },
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          visualMap: {
            show: false,
            min: 80,
            max: 600,
            inRange: {
              colorLightness: [0, 1]
            }
          },
          series: [
            {
              name: '访问来源',
              type: 'pie',
              radius: '55%',
              center: ['50%', '50%'],
              data: countbookcertM.sort(function (a, b) {
                return a.value - b.value
              }),
              roseType: 'radius',
              label: {
                normal: {
                  textStyle: {
                    color: 'rgba(255, 255, 255, 0.3)'
                  }
                }
              },
              labelLine: {
                normal: {
                  lineStyle: {
                    color: 'rgba(255, 255, 255, 0.3)'
                  },
                  smooth: 0.2,
                  length: 10,
                  length2: 20
                }
              },
              itemStyle: {
                normal: {
                  color: '#c23531',
                  shadowBlur: 200,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              },
              animationType: 'scale',
              animationEasing: 'elasticOut',
              animationDelay: function (idx) {
                return Math.random() * 200
              }
            }
          ]
        }
        this.chartPieLevel = echarts.init(document.getElementById('J_chartPieBoxLevel'))
        this.chartPieLevel.setOption(option)
        window.addEventListener('resize', () => {
          this.chartPieLevel.resize()
        })
      })
    }
  }
}
</script>
<style lang="scss">
  .mod-home {
    line-height: 1.5;
  }
  .mod-demo-echarts {
  .chart-box {
    min-height: 400px;
  }
  }
</style>

